import 'package:color_dart/RgbaColor.dart';
import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/components/labels/index.dart';
import 'package:im_flutter_sdk_example/jsonserialize/attention/data.dart';
import 'package:im_flutter_sdk_example/utils/constants.dart';

class AttentionItem extends StatefulWidget {
  final AttentionData item;
  final Function handleAttention;
  final bool isLast;
  final index;
  AttentionItem(
      {Key key, this.item, this.handleAttention, this.index, this.isLast})
      : super(key: key);

  @override
  _AttentionItemState createState() => _AttentionItemState();
}

class _AttentionItemState extends State<AttentionItem> {
  // 关注/取消
  handleAttention(bool follow, int index) {
    widget.handleAttention(follow, index);
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ListTile(
          title: Padding(
            padding: const EdgeInsets.only(bottom: 10),
            child: Row(
              children: [
                Text('${widget.item.name}', style: mainTitleStyle),
                Container(
                    margin: EdgeInsets.only(left: 4),
                    child: Row(children: [LabelExpert(), LabelAgent()]))
              ],
            ),
          ),
          subtitle: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              SizedBox(
                width: 9,
                height: 11,
                child: Image.asset(
                  'lib/assets/images/label/label_position.png',
                  fit: BoxFit.contain,
                ),
              ),
              Container(
                  child: Text('${widget.item.cityLabel}',
                      style: TextStyle(
                          color: rgba(163, 163, 163, 1), fontSize: 12)),
                  margin: EdgeInsets.only(left: 3)),
            ],
          ),
          leading: SizedBox(
            width: 60,
            height: 60,
            child: Container(
              child: ClipOval(
                child: Image.network(
                  '${widget.item.photo}',
                  width: 30,
                  height: 30,
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),
          trailing: Container(
            child: widget.item.follow
                ? Container(
                    height: 25,
                    width: 60,
                    child: OutlineButton(
                      padding: EdgeInsets.only(left: 0, right: 0),
                      shape: RoundedRectangleBorder(
                          side: BorderSide(
                              width: 2.0,
                              color: Colors.white,
                              style: BorderStyle.solid),
                          borderRadius: BorderRadius.only(
                            topRight: Radius.circular(20.0),
                            topLeft: Radius.circular(20.0),
                            bottomLeft: Radius.circular(20.0),
                            bottomRight: Radius.circular(20.0),
                          )),
                      borderSide:
                          BorderSide(color: rgba(221, 221, 221, 1), width: 1),
                      child: Text(
                        '已关注',
                        style: TextStyle(
                            color: rgba(163, 163, 163, 1), fontSize: 12),
                      ),
                      onPressed: () {
                        handleAttention(widget.item.follow, widget.index);
                      },
                    ),
                  )
                : Container(
                    height: 25,
                    width: 60,
                    child: OutlineButton(
                      padding: EdgeInsets.only(left: 0, right: 0),
                      shape: RoundedRectangleBorder(
                          side: BorderSide(
                              width: 2.0,
                              color: Colors.white,
                              style: BorderStyle.solid),
                          borderRadius: BorderRadius.only(
                            topRight: Radius.circular(20.0),
                            topLeft: Radius.circular(20.0),
                            bottomLeft: Radius.circular(20.0),
                            bottomRight: Radius.circular(20.0),
                          )),
                      borderSide:
                          BorderSide(color: rgba(42, 125, 250, 1), width: 1),
                      child: Text(
                        '关注',
                        style: TextStyle(
                            color: rgba(42, 125, 250, 1), fontSize: 12),
                      ),
                      onPressed: () =>
                          handleAttention(widget.item.follow, widget.index),
                    ),
                  ),
          ),
        ),
        widget.isLast
            ? Text('')
            : Divider(color: rgba(235, 235, 235, 1), height: 1, indent: 100)
      ],
    );
  }
}
